﻿using System.IO;
using System.Reflection;

namespace SyringeControl.AssemblySelectors
{
    /// <summary>
    /// Assembly selector loading assembly from path to its file
    /// </summary>
    public class PathAssemblySelector : IAssemblySelector
    {
        /// <summary>
        /// Path to assembly
        /// </summary>
        public string Path { get; set; }

        /// <summary>
        /// Initializes an instance <see cref="PathAssemblySelector"/>.
        /// </summary>
        /// <param name="path">path to assembly that should be loaded</param>
        public PathAssemblySelector(string path) { Path = path; }

        /// <summary>
        /// Selects <see cref="System.Reflection.Assembly"/>
        /// </summary>
        /// <returns>selected assembly</returns>
        public Assembly SelectAssembly()
        {
            if (File.Exists(Path))
                return Assembly.LoadFrom(Path);
            return null;
        }
    }
}
